package com.xd.dubbo.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.xd.dubbo.entity.OrderEntity;
import com.xd.dubbo.entity.UserEntity;
import com.xd.dubbo.globalTransaction.annotation.GlobalTransactional;
import com.xd.dubbo.mapper.orderDB.OrderMapper;
import com.xd.dubbo.mapper.userDB.UserMapper;
import com.xd.dubbo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

//import com.xd.dubbo.mapper.orderDB.OrderMapper;

/**
 * @author COFFICE
 * @version 1.0.0
 * @date 2019/3/9
 * @Description TODO
 */
@Service(timeout = 9000)
public class UserServiceImpl implements UserService {


    @Autowired
    UserMapper userMapper;

    @Autowired
    OrderMapper orderMapper;

    @Override
    public boolean login(String account, String pwd) {
        return true;
    }

    @Override
    @GlobalTransactional(endTransactional = true)
    @Transactional(transactionManager = "userTransactionManager")
    public Integer insert(UserEntity userEntity) throws Exception {

        OrderEntity orderEntity = new OrderEntity("provider", new Date());
//
        int i = 0;

//        i = orderMapper.insert(orderEntity);

        i = userMapper.insert(userEntity);
//        System.out.println(1/0);

        return i;
    }
}
